<template>
  <section class="my-commission">
    <div class="top- flex-col flex-around flex-middle">
      <div class="unit">总余额（元）</div>
      <div class="price">{{info.commission}}</div>
      <div class="btn flex flex-middle flex-center">
        <van-icon
          class="icon"
          name="orders-o"
          color="#FFFFFF"
        />规则说明
      </div>
    </div>
    <div class="item">
      <div class="flex flex-between flex-middle top">
        <div class="flex">
          <div class="text1">提现至</div>
          <van-icon
            class="icon"
            name="wechat"
            color="#24af41"
          />
          <div class="text2">微信钱包</div>
        </div>
        <div
          class="log"
          @click="routerTo('/pages/my/withdrawdetail/main')"
        >提现记录</div>
      </div>
      <div class="bottom">
        <div class="text3">提现金额</div>
        <div class="flex flex-end mt30">
          <span class="unit">￥</span>
          <input
            v-model="cashAmt"
            type="number"
            placeholder="请输入提现金额"
            placeholder-style="color:#C1C4C9"
          />
        </div>
        <button class="btn" @click="applyCash">申请提现</button>
      </div>
    </div>
  </section>
</template>
<script>
export default {
  data ()  {
    return {
      info: '',
      cashAmt: ''
    };
  },
  onLoad ()  {
    this.getCommissionDtl();
  },
  methods: {
    getCommissionDtl ()    {
      this.$api.getCommissionDtl().then(res =>      {
        this.info = res.data;
      })
    },
    applyCash ()    {
      if(this.cashAmt>this.info.commission){
        wx.showToast({
          title: '输入的金额大于实际金额', //提示的内容,
          icon: 'none', //图标,
          duration: 2000, //延迟时间,
          mask: true, //显示透明蒙层，防止触摸穿透,
          success: res => {}
        });
        return false;
      }
      this.$api.applyCash({cashAmt:this.cashAmt}).then(res =>      {
        if (res.code == 0)        {
          wx.showToast({
            title: res.msg, //提示的内容,
            icon: 'none', //图标,
            duration: 2000, //延迟时间,
            mask: true, //显示透明蒙层，防止触摸穿透,
            success: res =>            {
              this.getCommissionDtl();
            }
          });
        }
      })
    },
    routerTo (url)    {
      wx.navigateTo({ url });
    }
  }
};
</script>
<style lang="scss" scoped>
.my-commission {
  .top- {
    height: 160px;
    background: rgba(59, 184, 253, 1);
    .unit {
      font-size: 12px;
      font-family: PingFang;
      font-weight: bold;
      color: rgba(255, 255, 255, 1);
      line-height: 13px;
    }
    .price {
      font-size: 30px;
      font-family: DIN;
      font-weight: bold;
      color: rgba(255, 255, 255, 1);
      line-height: 13px;
    }
    .btn {
      width: 90px;
      height: 28px;
      border: 1px solid rgba(255, 255, 255, 1);
      border-radius: 14px;
      font-size: 12px;
      font-family: PingFang;
      font-weight: bold;
      color: rgba(255, 255, 255, 1);
      line-height: 28px;
      text-align: center;
      .icon {
        margin-right: 10px;
        margin-top: 3px;
      }
    }
  }
  .item {
    margin: 15px;
    background: white;
    padding: 0 25px;
    .top {
      padding: 25px 0;
      border-bottom: 1px solid #f7f7f7;
      .text1 {
        font-size: 14px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(64, 68, 76, 1);
        line-height: 13px;
        margin-right: 10px;
      }
      .text2 {
        margin-left: 5px;
        font-size: 15px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(193, 196, 201, 1);
        line-height: 13px;
      }
      .log {
        width: 55px;
        height: 18px;
        border: 1px solid rgba(59, 184, 253, 1);
        border-radius: 2px;
        color: #3bb8fd;
        font-size: 12px;
        text-align: center;
        line-height: 18px;
      }
    }
    .bottom {
      padding: 25px 0;
      .text3 {
        font-size: 15px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(46, 46, 46, 1);
        line-height: 13px;
      }
      .unit {
        font-size: 36px;
        font-family: PingFang;
        font-weight: bold;
        color: rgba(46, 46, 46, 1);
        line-height: 13px;
      }
      .btn {
        width: 295px;
        height: 44px;
        background: rgba(59, 184, 253, 1);
        border-radius: 5px;
        padding: 0;
        margin-top: 25px;
        border-top: 1px solid #f7f7f7;
        font-size: 15px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
      }
    }
  }
}
</style>
<style lang="scss">
page {
  background: #f7f7f7;
}
</style>